/*
 * Copyright (c) 2022 - 2032. www.vtuzx.com Inc. All Rights Reserved
 */
package com.vtuzx.kingdee.xqc_api.web;

import com.vtuzx.core.bean.dto.VtuzxToken;
import com.vtuzx.core.utils.VtuzxUtil;
import com.vtuzx.kingdee.xqc_api.service.IXqcConfigService;
import com.vtuzx.web.web.VtuzxApi;
import com.vtuzx.web.web.VtuzxControlParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 销售单接口配置相关接口
 */
@RequestMapping("/${vtuzx.fast.api.path}/${vtuzx.fast.api.version}/config/")
@RestController
public class XqcConfigController {

    /** 销售单接口配置服务 */
    @Autowired
    private IXqcConfigService configService;

    /**
     * 更新金蝶接口配置服务
     */
    @PostMapping("/save_config_kingdee")
    @VtuzxApi
    public Object saveKingdeeConfig(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> p) throws Exception {
        configService.updateKingdeeConfig(token, p);
        return null;
    }

    /**
     * 获取金蝶接口配置服务
     */
    @PostMapping("/get_config_kingdee")
    @VtuzxApi
    public Object getKingdeeConfig(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> p) throws Exception {
        return configService.getKingdeeConfig(token);
    }

    /**
     * 添加下推规则
     */
    @PostMapping("/add_push_rule")
    @VtuzxApi
    public Object addPushRule(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> p) throws Exception {
        configService.addPushRule(token, p);
        return null;
    }

    /**
     * 删除下推规则
     */
    @PostMapping("/delete_push_rules")
    @VtuzxApi
    public Object deletePushRules(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> p) throws Exception {
        configService.deletePushRules(token, VtuzxUtil.getObject(p, "ids"));
        return null;
    }

    /**
     * 更新下推规则
     */
    @PostMapping("/update_push_rule")
    @VtuzxApi
    public Object updatePushRule(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> p) throws Exception {
        configService.updatePushRule(token, p);
        return null;
    }

    /**
     * 获取下推规则
     */
    @PostMapping("/get_push_rule")
    @VtuzxApi
    public Object getPushRule(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> p) throws Exception {
        return configService.getPushRule(token, p);
    }
}
